/**
 * @author SaoE
 * @date 2025/3/25 20:59
 */
public class _24 {
    public ListNode swapPairs(ListNode head) {
        if(head == null || head.next == null){
            return head;
        }
        ListNode pre = new ListNode(0);
        pre.next = head;
        ListNode res = pre;
        while (pre.next != null && pre.next.next != null){
            ListNode first = pre.next;
            ListNode second = pre.next.next;

            pre.next = second;
            first.next = pre.next.next;
            second.next = first;

            pre = first;
        }

        return res.next;
    }
}
